const getNext = (n) => {
    n = String(n)
        //for of可以让代码更好读
    let sum = 0;
    for (let num of n) {
        sum += Math.pow(num, 2)
    }
    return sum;
}

var isHappy = function(n) {
    let map = new Map(); //ADT 抽象数据类型
    while (n != 1) {
        map.set(n, true);
        n = getNext(n);
        if (map.has(n)) return false
    }
    return true;
}
console.log(isHappy(29));